#include <QHash>
#include <QDebug>
#include "spatialgrid.h"
#include "Geography/geography.h"
#include "Geography/berthGrid.h"
#include "Geography/spatialObjectBase.h"


SpatialGrid::SpatialGrid(double lowerLeftLongitudeInDegree,
       double lowerLeftLatidueInDegree)
{
    this->lowerLeftLatidueInDegree=lowerLeftLatidueInDegree;
    this->lowerLeftLongitudeInDegree=lowerLeftLongitudeInDegree;
    this->northGrid=NULL;
    this->northEastGrid=NULL;
    this->eastGrid=NULL;
    this->southEastGrid=NULL;
    this->southGrid=NULL;
    this->southWestGrid=NULL;
    this->westGrid=NULL;
    this->northWestGrid=NULL;
}



SpatialGrid::~SpatialGrid()
{

}

QList <SpatialObjectBase*> SpatialGrid::getSpatialObjects()
{
    return hashIDSpatialObjectBase.values();
}


QHash<quint64, SpatialObjectBase *> SpatialGrid::getHashIDSpatialObjectBase() const
{
    return hashIDSpatialObjectBase;
}

void SpatialGrid::setSurrounding(SpatialGrid *northGrid,SpatialGrid *northEastGrid,SpatialGrid *eastGrid,
                                 SpatialGrid *southEastGrid,SpatialGrid *southGrid,
                    SpatialGrid *southWestGrid,SpatialGrid *westGrid,SpatialGrid *northWestGrid)
{
    this->northGrid=northGrid;
    this->northEastGrid=northEastGrid;
    this->eastGrid=eastGrid;
    this->southEastGrid=southEastGrid;
    this->southGrid=southGrid;
    this->southWestGrid=southWestGrid;
    this->westGrid=westGrid;
    this->northWestGrid=northWestGrid;

}

QList<SpatialObjectBase *> SpatialGrid::getSurroundingSpatialObjects()
{
    QList <SpatialObjectBase*> listSpatialObjectsBase;
    listSpatialObjectsBase.append(hashIDSpatialObjectBase.values());
    listSpatialObjectsBase.append(northGrid->getHashIDSpatialObjectBase().values());
    listSpatialObjectsBase.append(northEastGrid->getHashIDSpatialObjectBase().values());
    listSpatialObjectsBase.append(eastGrid->getHashIDSpatialObjectBase().values());
    listSpatialObjectsBase.append(southEastGrid->getHashIDSpatialObjectBase().values());
    listSpatialObjectsBase.append(southGrid->getHashIDSpatialObjectBase().values());
    listSpatialObjectsBase.append(southWestGrid->getHashIDSpatialObjectBase().values());
    listSpatialObjectsBase.append(westGrid->getHashIDSpatialObjectBase().values());
    listSpatialObjectsBase.append(northWestGrid->getHashIDSpatialObjectBase().values());
    return listSpatialObjectsBase;
}


void SpatialGrid::addOneSpatialObjectPointer(SpatialObjectBase *spatialObjectBase)
{
    hashIDSpatialObjectBase.insert(spatialObjectBase->getObjectID(),spatialObjectBase);
}

void SpatialGrid::removeOneSpatialObjectBasePointer(quint64 objectID)
{
    hashIDSpatialObjectBase.remove(objectID);
}

